package javaBean;

import JDBC.JDBC;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Message implements Serializable{
	private String mid;
	private String userid;
	private String title;
	private String context;
	private String username ;
	
	
	public Message() {
		mid ="";
		userid="";
		title = "";
		context = "";
	}
	
	public Message(String userid,String title,String context) {
		this.userid=userid;
		this.title =title;
		this.context = context;		
	}
	
	
	public String getmid() {
		return mid;
	}
	
	public String gettitle() {
		return title;
	}
	
	public String getuserid() {
		return userid;
	}
	
	public String getcontext() {
		return context;
	}
	
	
	
	public void setuserid(String userid) {
		this.userid = userid;
	}
	
	public void settitle(String title) {
		this.title = title;
	}

	public void setmid(String mid) {
		this.mid = mid;
	}

	public void setcontext(String context) {
		this.context = context;
	}


	public String getUsername(String userid) throws Exception {
		Connection conn = JDBC.getConnection();
		PreparedStatement ps = null;
	String name = "" ;
		ResultSet rs = null ;
		String query = "SELECT * from user where id = ? ";
		try {
			ps = conn.prepareStatement(query);
			ps.setString(1, userid);
			rs =  ps.executeQuery();
			if (rs.next()) {
				name = rs.getString("user_name");
			}
			return  name ;
		} catch (SQLException e) {
			System.out.println(e);
			return null;
		} finally {
			JDBC.release(ps, rs , conn);
		}

	}

}
